﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace BanHangCshap.DanhMuc.gkhtdl63.Thuchi
{
    public partial class frmChiLuongDuThu : Form
    {
        public frmChiLuongDuThu()
        {
            InitializeComponent();
        }

        Class.gkhtdl63.BLL.ThuChi3BLL xgThuChi3BLL = new BanHangCshap.Class.gkhtdl63.BLL.ThuChi3BLL();

        private void LoadPhieuthu()
        {
            gcPhieuthu2.DataSource = xgThuChi3BLL.ThuChi3_LayDanhsach(dtpTungay.EditValue, dtpDenngay.EditValue);
        }

        private void frmChiLuongDuThu_Load(object sender, EventArgs e)
        {
            dtpDenngay.EditValue = DateTime.Now;
            dtpTungay.EditValue = SDN.LayNgaydauthang();
            LoadPhieuthu();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            LoadPhieuthu();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmChiLuongDuThuChitiet frm = new frmChiLuongDuThuChitiet(true, null);
            frm.Tailai += new MyEvent_LoadData(frm_Tailai);
            frm.ShowDialog();
        }

        void frm_Tailai(object sender, ELoadData e)
        {
            if (e.IsLoadData)
            {
                LoadPhieuthu();
            }
        }

      private void btnSua_Click(object sender, EventArgs e)
        {
            try
            {
                frmChiLuongDuThuChitiet frm = new frmChiLuongDuThuChitiet(false, gvPhieuthu2.GetFocusedDataRow());
                frm.Tailai += new MyEvent_LoadData(frm_Tailai);
                frm.ShowDialog();
            }
            catch (Exception)
            {

            }
        }

        private void btnSua2_Click(object sender, EventArgs e)
        {
            btnSua_Click(null, null);
        }

        private void gvPhieuthu2_DoubleClick(object sender, EventArgs e)
        {
            btnSua_Click(null, null);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                if (xgThuChi3BLL.ThuChi3_Xoa(gvPhieuthu2.GetFocusedRowCellValue("Id")))
                {
                    frmThongbaoTimer frm = new frmThongbaoTimer();
                    frm.ShowDialog();
                    LoadPhieuthu();
                }
            }
            catch (Exception)
            {

            }
        }

        private void btnXoa2_Click(object sender, EventArgs e)
        {
            btnXoa_Click(null, null);
        }
    }
}
